package com.module.sysconfig.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.module.sysconfig.service.SfbzbService;
import com.support.helper.AjaxHelper;
import com.support.jdbc.Page;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;

/**
 * 收费标准
 * 1.收费标准保存
 * 2.删除收费标准
 * 3.收费标准的列表查询
 * 4.Id查询收费标准
 * 5.修改收费标准
 * @author James
 *
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig/sfbz")
public class SfbzController extends ControllerSupport{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private SfbzbService sfbzbService;

	/**
	 * 收费标准保存
	 * @throws Exception
	 */
	@RequestMapping("/saveSfbzb")
	public void saveFjpzb() throws Exception
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			
			
			sfbzbService.saveSfbzb(paramsMap);
			returnJSONView(AjaxHelper.toJSON(paramsMap, AjaxHelper.SUCCESS, "保存成功.."));
		}
		catch (Exception e) 
		{
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "保存失败.."));
			logger.error(e.getMessage());
		}
		
	}
	
	/**
	 * del收费标准
	 * @throws Exception
	 */
	@RequestMapping("/delSfbzb")
	public void delFjpzb() throws Exception
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			
			String ID = paramsMap.get("ID");
			if(StringUtils.isNumeric(ID)){
				sfbzbService.delSfbzb(Long.parseLong(ID));
			}
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除成功.."));
		}
		catch (Exception e)
		{
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "删除失败.."));
			logger.error(e.getMessage());
		}
	}
	
	/**
	 * 收费标准列表查询
	 * @throws Exception
	 */
	@RequestMapping("/queryRecordSfbzb")
	public void queryRecordFjpzb() throws Exception
	{
		try
		{
			Page page = this.getParamsPage();
			returnJSONView(AjaxHelper.toJSON(sfbzbService.queryRecordSfbzb(page), AjaxHelper.SUCCESS, "查询成功"));
		}
		catch (Exception e) 
		{
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "查询失败..."));
			logger.error(e.getMessage());
		}
	}
	
	/**
	 * id查询收费标准
	 * @throws Exception
	 */
	@RequestMapping("/querySfbzb")
	public void queryFjpzb() throws Exception
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			String ID = paramsMap.get("ID");
			if(StringUtils.isNumeric(ID)){
				returnJSONView(AjaxHelper.toJSON(sfbzbService.querySfbzb(Long.parseLong(ID)), AjaxHelper.SUCCESS, "查询成功"));
			}
		}
		catch (Exception e) 
		{
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "查询失败..."));
			logger.error(e.getMessage());
		}
	}
	
	/**
	 * 修改收费标准
	 * @throws Exception
	 */
	@RequestMapping("/updateSfbzb")
	public void updateFjpzb(Long id) throws Exception
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			
			sfbzbService.updateSfbzb(paramsMap);
			returnJSONView(AjaxHelper.toJSON(paramsMap, AjaxHelper.SUCCESS, "修改成功"));
		}
		catch (Exception e) 
		{
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "修改失败"));
			logger.error(e.getMessage());
		}
	}
	
}
